package com.xujc.controller;

import com.opensymphony.xwork2.ActionSupport;
import com.xujc.dao.IUserDAO;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by xujc on 6/21/15.
 */
public class DoregistAction extends ActionSupport {
    private IUserDAO mUserDAO;
    private String mPassword;
    private String mEmail;
    private String mName;

    @Override
    public String execute() throws Exception {
        int register = mUserDAO.register(mEmail, mPassword, mName);
        HttpServletResponse response = ServletActionContext.getResponse();
        Cookie uid = new Cookie("uid", String.valueOf(register));
        uid.setMaxAge(60*60*24);
        response.addCookie(uid);
        return SUCCESS;
    }

    public String getPassword() {
        return mPassword;
    }

    public void setPassword(String password) {
        mPassword = password;
    }

    public String getEmail() {
        return mEmail;
    }

    public void setEmail(String email) {
        mEmail = email;
    }

    public String getName() {
        return mName;
    }

    public void setName(String name) {
        mName = name;
    }

    public void setUserDAO(IUserDAO userDAO) {
        mUserDAO = userDAO;
    }
}
